//
//  DetailViewController.m
//  Daybook
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 zhangbin. All rights reserved.
//

#import "DetailViewController.h"
#import "Common.h"

@interface DetailViewController ()<DetailViewDelegate>

@property (nonatomic, strong) BaseView *navigationView;
@property (nonatomic, strong) BaseButton *backButton;
@property (nonatomic, strong) LeftTitleButton *dateButton;
@property (nonatomic, strong) BaseButton *moreButton;
@property (nonatomic, strong) DetailView *detailView;

@property (nonatomic, strong) UIView *bottomLineView;


@end
@implementation DetailViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createnavigationView];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createView];
}

- (void)createnavigationView {
    self.navigationView = [[BaseView alloc] initWithFrame:CGRectMake(0, 0, MAIN_WIDTH, 64)];
    [self.view addSubview:_navigationView];
    self.navigationView.backgroundColor = BGCOLOR;
    
    self.backButton = ({
        BaseButton *tempButton = [BaseButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake(5 / 414.0 * MAIN_WIDTH, 30, 30 / 414.0 * MAIN_WIDTH, 25 / 414.0 * MAIN_WIDTH);
        [self.navigationView addSubview:tempButton];
        [tempButton setImage:[UIImage imageNamed:@"whiteFanhui.png"] forState:UIControlStateNormal];
        [tempButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        tempButton;
    });

    self.dateButton = ({
        LeftTitleButton *tempButton = [LeftTitleButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake(35 / 414.0 * MAIN_WIDTH, 30, 128 / 414.0 * MAIN_WIDTH, 25 / 414.0 * MAIN_WIDTH);
        [self.navigationView addSubview:tempButton];
        [tempButton addTarget:self action:@selector(dateButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [tempButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        tempButton.backgroundColor = [UIColor blackColor];
        tempButton.titleLabel.textAlignment = NSTextAlignmentLeft;
        tempButton;
    });
    
//    self.moreButton = ({
//        BaseButton *tempButton = [BaseButton buttonWithType:UIButtonTypeCustom];
//        tempButton.frame = CGRectMake(370 / 414.0 * MAIN_WIDTH, 30, 30 / 414.0 * MAIN_WIDTH, 25 / 414.0 * MAIN_WIDTH);
//        [self.navigationView addSubview:tempButton];
//        [tempButton setImage:[UIImage imageNamed:@"fanhui.png"] forState:UIControlStateNormal];
//        [tempButton addTarget:self action:@selector(moreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        tempButton;
//    });
    
    self.bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 63, MAIN_WIDTH, 1)];
    [self.view addSubview:_bottomLineView];
    _bottomLineView.backgroundColor = LINE_COLOR;
}

- (void)createView {
    self.detailView = [[DetailView alloc] initWithFrame:CGRectMake(0, 64, MAIN_WIDTH, MAIN_HEIGHT - 64)];
    [self.view addSubview:_detailView];
    
    _detailView.today = [NSDate date];
//    _detailView.date = _detailView.today;
    _detailView.delegate = self;
    
    NSInteger year = [[CalendarTool shareCalendarTool] year:self.detailView.today];
    NSInteger month = [[CalendarTool shareCalendarTool] month:self.detailView.today];
    [self.dateButton setTitle:[NSString stringWithFormat:@"%04ld年%02ld月", year, month] forState: UIControlStateNormal];
    
}


- (void)backButtonAction:(UIButton *)button {
    [self popToBeforePage];
}

- (void)dateButtonAction:(UIButton *)button {
    [self popToBeforePage];
}

- (void)moreButtonAction:(UIButton *)button {
    [self popToBeforePage];
}

- (void)popToBeforePage {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)dateButtonTitleString:(NSString *)titleString {
    [self.dateButton setTitle:titleString forState: UIControlStateNormal];

}

- (void)jumpToIntroduceViewControllerWithModel:(RightDayModel *)model {
    IntroduceViewController *introduceVC = [IntroduceViewController new];
    introduceVC.model = model;
    [self.navigationController pushViewController:introduceVC animated:YES];
}


@end
